{include file="base/_meta" /}
</head>
<body>

<form class="layui-form model-form" id="modelAuthForm" lay-filter="modelAuthForm">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off"
                   class="layui-input" value="{$content['label']|default=''}">
        </div>
        <div class="layui-input-inline">
            {if condition="isset($content['required']) && $content['required']=='true'"}<input type="checkbox" name="required" title="必答" checked>
            {else /} <input type="checkbox" name="required" title="必答">
            {/if}
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">大小限制</label>
        <div class="layui-input-block">
            <input type="number" name="size" placeholder="请输入" class="layui-input inline-block" style="width: 160px;" value="0">
            <span>&nbsp;M；(0表示不限制)</span>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">文件类型</label>
        <div class="layui-input-block">
            <input type="radio" name="subtype" value="video" title="视频">
            <input type="radio" name="subtype" value="image" title="图片" checked>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <button class="layui-btn" lay-filter="*" lay-submit>完成编辑</button>
        </div>
    </div>
</form>

{include file="base/_script" /}
<script>
    layui.use(['layer', 'form','notice'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , form = layui.form
            , name = "radio-<?php echo microtime(true)*10000;?>"
            , content = {}
            ,notice = layui.notice;

        form.on('submit(*)', function (data) {
            let field = data.field
            let required = false
            if(field.required == 'on'){
                required = true
            }
            content.label = field.title
            content.name = name
            content.required = required
            content.type = 'file'
            content.size = field.size
            content.subtype = field.subtype

            $.post("{:url('question/saveTemp2')}",{content:content,question_id:"{$question_id}",index:"{$index}",insert:"{$insert}"},function (ret) {
                if (ret.code == 0){
                    layer.msg(ret.msg,{icon:6,time:1500},function () {
                        parent.layer.closeAll();
                    })
                }else{
                    layer.msg(ret.msg,{icon:5,time:1500})
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })

</script>


</body>
</html>
